const { ccclass, property } = cc._decorator;

@ccclass
export default class MyTouch extends cc.Component {
    @property(cc.Node)
	nodeLine: cc.Node = null

	/**
	 * @description: 设置开始位置
	 * @param {cc.v2} 开始位置
	 * @return:
	 */
	setStartPos(pos: cc.Vec2) {
		this.node.position = pos;
		this.nodeLine.width = 0;
	}

	/**
	 * @description: 设置结束位置
	 * @param {cc.v2} pos 结束位置
	 * @return:
	 */
	setEndPos(pos: cc.Vec2) {
		let offset = pos.sub(this.node.position);
		this.nodeLine.width = offset.mag();
		let degree = cc.misc.radiansToDegrees(offset.signAngle(cc.v2(-1, 0)));

		this.node.rotation = degree;
		// 限定视野
		if (degree > 90) {
			this.node.rotation = 90;
		} else if (degree < -90) {
			this.node.rotation = -90;
		}
	}

	/**
	 * @description: 获取力量大小
	 * @param {type}
	 * @return:
	 */
	getForce() {
		if (this.nodeLine.width > 200) {
			return 1;
		}
		return this.nodeLine.width / 200;
	}

	// onLoad () {}

	start() {}

	// update (dt) {}
}
